package com.jcgyl.export.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.jcgyl.export.entity.Post;
import com.jcgyl.export.entity.PostQueryModel;
import com.jcgyl.export.entity.ViewPost;
import com.jcgyl.export.service.PostService;
import com.jcgyl.export.util.entity.Result;

@RestController
@RequestMapping("/post")
public class PostController {
	@Autowired
	private PostService postService;

	// 获取所有的客户信息
	@PostMapping("/findAllPost")
	public Map<String, Object> doFindAllpost(@RequestBody PostQueryModel postFilter) {
		String postName = postFilter.getFilter().getPostName();
		String departmentName = postFilter.getFilter().getDepartmentName();
		System.out.println("接受客户前台客户信息" + "postName:" + postName + "departmentName:" + departmentName);
		int pageIndex = postFilter.getPageIndex();
		int pageSize = postFilter.getPageSize();
		System.out.println("pageIndex:" + pageIndex + "pageSize:" + pageSize);
		Map<String, Object> map = postService.findAllPost(postName, departmentName, pageSize, pageIndex);
		return map;
	}

	// 添加或修改客户信息
	@RequestMapping("/addOrUpdatePost")
	public Result doAndpost(@RequestBody ViewPost viewpost) {
		String name = viewpost.getPostName();
		String departmentName = viewpost.getDepartmentName();
		System.out.println("添加客户的姓名" + ":" + name + "departmentName:" + departmentName);
		if (viewpost.getId() == null) {
			return postService.addPost(viewpost);
		} else {
			return postService.updatePost(viewpost);
		}
	}

	// 删除客户信息
	@RequestMapping("/deletepost")
	public Result Delete(@RequestBody ViewPost viewpost) {
		int postId = viewpost.getId();
		return postService.deletePost(postId);
	}
	/**
	 * 根据id查询数据
	 * @param departmentId
	 * @return
	 * JL
	 */
	@PostMapping("/doFindPost")
	public List<Post> doFindPost(@RequestBody int departmentId) {
		System.out.println(departmentId);
		List<Post> list = postService.findPost(departmentId);
		return list;
	}
	@PostMapping("/findPostZtree")
	public List<Post> doFindPostZtree() {
		List<Post> list = postService.findZtreeObject();
		return list;
	}
}
